<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="供应商名称
" prop="supplierName">
        <el-input
          v-model="queryParams.supplierName"
          placeholder="请输入供应商名称
"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商编码
" prop="supplierCode">
        <el-input
          v-model="queryParams.supplierCode"
          placeholder="请输入供应商编码
"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属仓库
" prop="warehouse">
        <el-input
          v-model="queryParams.warehouse"
          placeholder="请输入所属仓库
"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品物料
" prop="materialName">
        <el-input
          v-model="queryParams.materialName"
          placeholder="请输入产品物料
"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编码
" prop="materialCode">
        <el-input
          v-model="queryParams.materialCode"
          placeholder="请输入物料编码
"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料属性
" prop="materialProperties">
        <el-input
          v-model="queryParams.materialProperties"
          placeholder="请输入物料属性
"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料类型
" prop="materialType">
        <el-select v-model="queryParams.materialType" placeholder="请选择物料类型
" clearable>
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="规格型号
" prop="specifications">
        <el-input
          v-model="queryParams.specifications"
          placeholder="请输入规格型号
"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料状态
" prop="materialStatus">
        <el-select v-model="queryParams.materialStatus" placeholder="请选择物料状态
" clearable>
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="主单位(物料)" prop="mainUnit">
        <el-input
          v-model="queryParams.mainUnit"
          placeholder="请输入主单位(物料)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="换算率" prop="conversionRate">
        <el-input
          v-model="queryParams.conversionRate"
          placeholder="请输入换算率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="采购单位" prop="purchasingUnit">
        <el-input
          v-model="queryParams.purchasingUnit"
          placeholder="请输入采购单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计算单价(ml/g - 元)" prop="calculateUnitPrice">
        <el-input
          v-model="queryParams.calculateUnitPrice"
          placeholder="请输入计算单价(ml/g - 元)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最新单价(ml/g-元)" prop="latestUnitPrice">
        <el-input
          v-model="queryParams.latestUnitPrice"
          placeholder="请输入最新单价(ml/g-元)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最新单价(主单位-元)
" prop="latestUnitPriceMain">
        <el-input
          v-model="queryParams.latestUnitPriceMain"
          placeholder="请输入最新单价(主单位-元)
"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="(不含运税)单价/元" prop="unitPriceNo">
        <el-input
          v-model="queryParams.unitPriceNo"
          placeholder="请输入(不含运税)单价/元"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="(含税不含运价)单价/元" prop="unitPriceTax">
        <el-input
          v-model="queryParams.unitPriceTax"
          placeholder="请输入(含税不含运价)单价/元"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="(含运不含税)单价/元" prop="unitPriceFreight">
        <el-input
          v-model="queryParams.unitPriceFreight"
          placeholder="请输入(含运不含税)单价/元"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="(含运税)单价/元" prop="unitPriceAll">
        <el-input
          v-model="queryParams.unitPriceAll"
          placeholder="请输入(含运税)单价/元"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="价格日期" prop="priceDate">
        <el-date-picker clearable
          v-model="queryParams.priceDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择价格日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="最小价格单位" prop="miniPriceUnit">
        <el-input
          v-model="queryParams.miniPriceUnit"
          placeholder="请输入最小价格单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="remarks">
        <el-input
          v-model="queryParams.remarks"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="平均单价" prop="averageUnitPrice">
        <el-input
          v-model="queryParams.averageUnitPrice"
          placeholder="请输入平均单价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="采购交期" prop="procurementLeadTime">
        <el-date-picker clearable
          v-model="queryParams.procurementLeadTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择采购交期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['md:venrprice:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['md:venrprice:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['md:venrprice:remove']"
        >删除</el-button>
        <el-col :span="1.5">
              <el-button
                type="success"
                plain
                icon="el-icon-refresh"
                size="mini"
                @click="handleSync"
               v-hasPermi="['md:venrprice:sync']"
              >数据同步</el-button>
              </el-col>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['md:venrprice:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="listVenrprice" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="venrpriceId" />
      <el-table-column label="供应商名称
" align="center" prop="supplierName" />
      <el-table-column label="供应商编码
" align="center" prop="supplierCode" />
      <el-table-column label="所属仓库
" align="center" prop="warehouse" />
      <el-table-column label="产品物料
" align="center" prop="materialName" />
      <el-table-column label="物料编码
" align="center" prop="materialCode" />
      <el-table-column label="物料属性
" align="center" prop="materialProperties" />
      <el-table-column label="物料类型
" align="center" prop="materialType" />
      <el-table-column label="规格型号
" align="center" prop="specifications" />
      <el-table-column label="物料状态
" align="center" prop="materialStatus" />
      <el-table-column label="主单位(物料)" align="center" prop="mainUnit" />
      <el-table-column label="换算率" align="center" prop="conversionRate" />
      <el-table-column label="采购单位" align="center" prop="purchasingUnit" />
      <el-table-column label="计算单价(ml/g - 元)" align="center" prop="calculateUnitPrice" />
      <el-table-column label="最新单价(ml/g-元)" align="center" prop="latestUnitPrice" />
      <el-table-column label="最新单价(主单位-元)
" align="center" prop="latestUnitPriceMain" />
      <el-table-column label="(不含运税)单价/元" align="center" prop="unitPriceNo" />
      <el-table-column label="(含税不含运价)单价/元" align="center" prop="unitPriceTax" />
      <el-table-column label="(含运不含税)单价/元" align="center" prop="unitPriceFreight" />
      <el-table-column label="(含运税)单价/元" align="center" prop="unitPriceAll" />
      <el-table-column label="价格日期" align="center" prop="priceDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.priceDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最小价格单位" align="center" prop="miniPriceUnit" />
      <el-table-column label="备注" align="center" prop="remarks" />
      <el-table-column label="平均单价" align="center" prop="averageUnitPrice" />
      <el-table-column label="采购交期" align="center" prop="procurementLeadTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.procurementLeadTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['md:venrprice:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['md:venrprice:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="供应商名称
" prop="supplierName">
          <el-input v-model="form.supplierName" placeholder="请输入供应商名称
" />
        </el-form-item>
        <el-form-item label="供应商编码
" prop="supplierCode">
          <el-input v-model="form.supplierCode" placeholder="请输入供应商编码
" />
        </el-form-item>
        <el-form-item label="所属仓库
" prop="warehouse">
          <el-input v-model="form.warehouse" placeholder="请输入所属仓库
" />
        </el-form-item>
        <el-form-item label="产品物料
" prop="materialName">
          <el-input v-model="form.materialName" placeholder="请输入产品物料
" />
        </el-form-item>
        <el-form-item label="物料编码
" prop="materialCode">
          <el-input v-model="form.materialCode" placeholder="请输入物料编码
" />
        </el-form-item>
        <el-form-item label="物料属性
" prop="materialProperties">
          <el-input v-model="form.materialProperties" placeholder="请输入物料属性
" />
        </el-form-item>
        <el-form-item label="物料类型
" prop="materialType">
          <el-select v-model="form.materialType" placeholder="请选择物料类型
">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="规格型号
" prop="specifications">
          <el-input v-model="form.specifications" placeholder="请输入规格型号
" />
        </el-form-item>
        <el-form-item label="物料状态
">
          <el-radio-group v-model="form.materialStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="主单位(物料)" prop="mainUnit">
          <el-input v-model="form.mainUnit" placeholder="请输入主单位(物料)" />
        </el-form-item>
        <el-form-item label="换算率" prop="conversionRate">
          <el-input v-model="form.conversionRate" placeholder="请输入换算率" />
        </el-form-item>
        <el-form-item label="采购单位" prop="purchasingUnit">
          <el-input v-model="form.purchasingUnit" placeholder="请输入采购单位" />
        </el-form-item>
        <el-form-item label="计算单价(ml/g - 元)" prop="calculateUnitPrice">
          <el-input v-model="form.calculateUnitPrice" placeholder="请输入计算单价(ml/g - 元)" />
        </el-form-item>
        <el-form-item label="最新单价(ml/g-元)" prop="latestUnitPrice">
          <el-input v-model="form.latestUnitPrice" placeholder="请输入最新单价(ml/g-元)" />
        </el-form-item>
        <el-form-item label="最新单价(主单位-元)
" prop="latestUnitPriceMain">
          <el-input v-model="form.latestUnitPriceMain" placeholder="请输入最新单价(主单位-元)
" />
        </el-form-item>
        <el-form-item label="(不含运税)单价/元" prop="unitPriceNo">
          <el-input v-model="form.unitPriceNo" placeholder="请输入(不含运税)单价/元" />
        </el-form-item>
        <el-form-item label="(含税不含运价)单价/元" prop="unitPriceTax">
          <el-input v-model="form.unitPriceTax" placeholder="请输入(含税不含运价)单价/元" />
        </el-form-item>
        <el-form-item label="(含运不含税)单价/元" prop="unitPriceFreight">
          <el-input v-model="form.unitPriceFreight" placeholder="请输入(含运不含税)单价/元" />
        </el-form-item>
        <el-form-item label="(含运税)单价/元" prop="unitPriceAll">
          <el-input v-model="form.unitPriceAll" placeholder="请输入(含运税)单价/元" />
        </el-form-item>
        <el-form-item label="价格日期" prop="priceDate">
          <el-date-picker clearable
            v-model="form.priceDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择价格日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="最小价格单位" prop="miniPriceUnit">
          <el-input v-model="form.miniPriceUnit" placeholder="请输入最小价格单位" />
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="平均单价" prop="averageUnitPrice">
          <el-input v-model="form.averageUnitPrice" placeholder="请输入平均单价" />
        </el-form-item>
        <el-form-item label="采购交期" prop="procurementLeadTime">
          <el-date-picker clearable
            v-model="form.procurementLeadTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择采购交期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listVenrprice, getVenrprice, delVenrprice, addVenrprice, updateVenrprice ,syncVenrprice} from "@/api/mes/md/venrprice";

export default {
  name: "List",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      listVenrprice: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        supplierName: null,        supplierCode: null,        warehouse: null,        materialName: null,        materialCode: null,        materialProperties: null,        materialType: null,        specifications: null,        materialStatus: null,        mainUnit: null,        conversionRate: null,        purchasingUnit: null,        calculateUnitPrice: null,        latestUnitPrice: null,        latestUnitPriceMain: null,        unitPriceNo: null,        unitPriceTax: null,        unitPriceFreight: null,        unitPriceAll: null,        priceDate: null,        miniPriceUnit: null,        remarks: null,        averageUnitPrice: null,        procurementLeadTime: null,      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listVenrprice(this.queryParams).then(response => {
        this.listVenrprice = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        venrpriceId: null,        supplierName: null,        supplierCode: null,        warehouse: null,        materialName: null,        materialCode: null,        materialProperties: null,        materialType: null,        specifications: null,        materialStatus: "0",        mainUnit: null,        conversionRate: null,        purchasingUnit: null,        calculateUnitPrice: null,        latestUnitPrice: null,        latestUnitPriceMain: null,        unitPriceNo: null,        unitPriceTax: null,        unitPriceFreight: null,        unitPriceAll: null,        priceDate: null,        miniPriceUnit: null,        remarks: null,        averageUnitPrice: null,        procurementLeadTime: null,        delFlag: null,        createBy: null,        createTime: null,        updateBy: null,        updateTime: null      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.venrpriceId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const venrpriceId = row.venrpriceId || this.ids
      getVenrprice(venrpriceId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.venrpriceId != null) {
            updateVenrprice(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addVenrprice(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 同步数据按钮操作 */
    handleSync() {
            if(this.loading){
              this.$modal.message("正常进行中，请不要重复点击...")
            }
            this.loading = true;
            this.$modal.confirm('是否确认同步数据？').then(function() {
              return syncVenrprice();
            }).then(() => {
              this.getList();
              this.$modal.msgSuccess("同步成功");
            }).catch(() => {});
          },
    /** 删除按钮操作 */
    handleDelete(row) {
      const venrpriceIds = row.venrpriceId || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + venrpriceIds + '"的数据项？').then(function() {
        return delVenrprice(venrpriceIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/mes/md/venrprice/export', {
        ...this.queryParams
      }, `list_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
